package gunfire.actions;

import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.DamageAction;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.AbstractCreature;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.ui.panels.EnergyPanel;

public class ConcealedAmmoAction extends AbstractGameAction {

    private AbstractPlayer p;
    private AbstractMonster m;
    private int firstDamage;
    private int damageGap;
    private boolean freeToPlayOnce;
    private int energyOnUse;

    public ConcealedAmmoAction(AbstractPlayer p, AbstractMonster m, int firstDamage, int damageGap, boolean freeToPlayOnce, int energyOnUse){
        this.m = m;
        this.p = p;
        this.firstDamage = firstDamage;
        this.damageGap = damageGap;
        this.freeToPlayOnce = freeToPlayOnce;
        this.energyOnUse = energyOnUse;
    }

    @Override
    public void update() {
        int effect = EnergyPanel.totalCount;
        if (this.energyOnUse != -1) {
            effect = this.energyOnUse;
        }

        if (this.p.hasRelic("Chemical X")) {
            effect += 2;
            this.p.getRelic("Chemical X").flash();
        }

        if (effect > 0) {
            int damage = this.firstDamage;
            for(int i = 0; i < effect; ++i) {
                this.addToBot(new DamageAction(this.m, new DamageInfo(this.p, damage, DamageInfo.DamageType.HP_LOSS), AttackEffect.BLUNT_LIGHT));
                damage += this.damageGap;
            }

            if (!this.freeToPlayOnce) {
                this.p.energy.use(EnergyPanel.totalCount);
            }
        }

        this.isDone = true;
    }
}
